<template>
    <div class="edu-page-warp">
        <condition-card @reset="resetQuery" @search="searchData">
            <el-form label-width="120px" label-position="right" label-suffix=":">
            <!--事件-->
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-form-item :label="$t('minor.major.minorGrade')">
                            <el-date-picker
                                v-model="queryParams.grade"
                                value-format="yyyy"
                                type="year"
                                clearable
                                :placeholder="$t('message.plsSelect')"
                                @change="queryCampusProfessions(1)"
                                style="width: 100%"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('minor.major.college')">
                            <DictSelect
                                v-model="queryParams.college"
                                :data="options.college"
                                :clearable="canSelectFaculty"
                                :filterable="true"
                                @change="queryCampusProfessions(1)"
                                style="width: 100%;"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="辅修专业">
                            <DictSelect
                                v-model="queryParams.profession"
                                :data="options.profession"
                                :clearable="true"
                                :filterable="true"
                                style="width:100%;"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="8">
                        <el-form-item label="进阶层次">
                            <DictSelect
                                v-model="queryParams.advancedLevel"
                                :data="options.advancedLevel"
                                clearable
                                style="width:100%;"
                            ></DictSelect>
                        </el-form-item>
                    </el-col> -->
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-form-item :label="$t('minor.culture.cultureStatus')">
                            <DictSelect
                                v-model="queryParams.status"
                                :data="options.pushStatus"
                                clearable
                                style="width:100%;"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </condition-card>
        <el-card shadow="never">
            <div class="first_title">微专业培养方案关联列表</div>
            <div class="btn">
                <div style="float:left;">
                    <el-input
                        placeholder="请输入学号或姓名搜索"
                        prefix-icon="el-icon-search"
                        v-model="queryParams.keyWord"
                        style="width:240px;"
                        @change="searchRelevance"
                        @keyup.native.enter="searchData"
                    ></el-input>
                </div>
                <el-button type="danger" @click="batchCancelRelevance">取消关联</el-button>
                <el-button type="primary" @click="batchRelevanceCultureScheme">关联方案</el-button>
                <el-button type="primary" @click="autoAssociate">自动关联</el-button>
            </div>
            <EduTable
                @page-change="pageChange"
                :data="tableData.list"
                :total="tableData.total_"
                :pageSize="page.pageSize_"
                :pageNum="page.pageNum_"
                @selection-change="handleSelectionChange"
            >
                <el-table-column label="辅修年级" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.entranceTerm}}</template>
                </el-table-column>
                <el-table-column label="学号" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.studentId}}</template>
                </el-table-column>
                <el-table-column label="姓名" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.studentName}}</template>
                </el-table-column>
                <!-- <el-table-column label="进阶层次" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.advancedLevelName}}</template>
                </el-table-column> -->
                <el-table-column :label="$t('minor.major.college')" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.departmentIdI18n}}</template>
                </el-table-column>
                <el-table-column label="辅修专业" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.majorNameCn}}</template>
                </el-table-column>
                <el-table-column label="培养方案" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            @click="previewCulture(scope.row)"
                            size="mini"
                        >{{scope.row.cultureName}}</el-button>
                    </template>
                </el-table-column>
                <el-table-column label="发布状态" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <el-tag
                            :type="scope.row.statusRelation === 2 ? 'success' : 'danger'"
                            size="mini"
                            disable-transitions
                        >{{ getPushLable(scope.row.statusRelation) }}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column :label="$t('message.operating')">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            @click="relevanceCultureScheme(scope.row)"
                            v-if="scope.row.statusRelation === 1"
                            size="mini"
                        >关联方案</el-button>
                        <el-button
                            type="text"
                            @click="cancelRelevance(scope.row)"
                            v-if="scope.row.statusRelation === 2 "
                            size="mini"
                        >取消关联</el-button>
                    </template>
                </el-table-column>
            </EduTable>
        </el-card>
        <edu-dialog ref="relevanceDialog" title="关联方案" width="85%" :autoHeight="true"  @close="relevanceDialogClose" @open="resetSchemeForm">
            <condition-card @reset="resetSchemeForm" @search="searchSchemeData">
                <!--事件-->
                <el-form label-width="120px" label-position="right" label-suffix=":">
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item :label="$t('minor.major.minorGrade')">
                                <el-date-picker
                                    v-model="dialogForm.grade"
                                    value-format="yyyy"
                                    @change="queryCampusProfessions(2)"
                                    type="year"
                                    clearable
                                    :placeholder="$t('message.plsSelect')"
                                    style="width: 100%"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('minor.major.college')"> 
                                <DictSelect
                                    v-model="dialogForm.college"
                                    :data="options.college"
                                    :clearable="true"
                                    :filterable="true"
                                    @change="queryCampusProfessions(2)"
                                    style="width: 100%;"
                                ></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="辅修专业">
                                <DictSelect
                                    v-model="dialogForm.profession"
                                    :data="options.dialogProfession"
                                    :clearable="true"
                                    :filterable="true"
                                    style="width:100%;"
                                ></DictSelect>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <!-- <el-row>
                    <el-col :span="8">
                        <el-form-item label="进阶层次">
                            <DictSelect
                                v-model="dialogForm.advancedLevel"
                                :data="options.advancedLevel"
                                clearable
                                style="width:100%;"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                </el-row> -->
            </condition-card>
            <div>
                <div class="title_div">辅修微专业培养方案</div>
                <div class="search_div">
                    <el-input
                        placeholder="请输入培养方案名称搜索"
                        prefix-icon="el-icon-search"
                        v-model="dialogForm.cultureSchemeName"
                        style="width:240px;"
                        @change="inputSearch"
                        @keyup.enter.native="inputSearch"
                    ></el-input>
                </div>
            </div>
            <EduTable
                :selection="false"
                :order="false"
                ref="schemeDataTable"
                :pageSize="culturePage.pageSize_"
                :pageNum="culturePage.pageNum_"
                @page-change="schemeChangePage"
                :data="schemeTableData.list"
                :total="schemeTableData.total_"
            >
                <el-table-column width="30">
                    <template slot-scope="scope">
                        <el-radio v-model="templateRadio" :label="scope.row.id">&nbsp;</el-radio>
                    </template>
                </el-table-column>
                <el-table-column label="微专业方案名称" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.name}}</template>
                </el-table-column>
                <el-table-column label="辅修年级" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.minorGrade}}</template>
                </el-table-column>
                <el-table-column :label="$t('minor.major.college')" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.collegeCodeI18n}}</template>
                </el-table-column>
                <el-table-column label="辅修专业" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.majorNameCn}}</template>
                </el-table-column>
                <!-- <el-table-column label="进阶层次" width="180" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.advancedLevelName}}</template>
                </el-table-column> -->
            </EduTable>
            <span slot="buttons">
                <el-button @click="closeSchemeDialog">取消</el-button>
                <el-button type="primary" @click="confirmSchemeDialog">确定</el-button>
            </span>
        </edu-dialog>
        <el-dialog
            :visible.sync="dialogOk"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            width="40%"
        >
             <div slot="title" style="margin-top:-8px">
                <i style="font-size:24px;color: #1a68df;vertical-align:middle" class="el-icon-warning"></i>
                <span style="font-size:18px;font-weight:650;color:#4c5c70;vertical-align:middle">自动关联</span>
            </div>
             <el-row  style="margin: 10px 0;">
                <el-col v-if="associateModelType === 'auto'">
                    <div v-if="$store.state.language == 'cn'">
                        <P>本次关联培养方案 {{canAssociateNum}} 个，是否关联?</P>
                    </div>
                    <div v-if="$store.state.language == 'en'">
                        <P>There are {{canAssociateNum}} associated culture schemes in this study. Whether to continue operation or not ?</P>
                    </div>
                </el-col>
                <el-col v-if="associateModelType === 'result'">
                    <p>本次关联培养方案{{tipsData.totalCount}}个，关联成功{{tipsData.successCount}}个，关联失败{{tipsData.failCount}}个</p>
                    <a
                        href="#"
                        @click="downloadfile"
                    >{{tipsData.objectkey && tipsData.objectkey.substr(10)}}</a>
                </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button @click="cancelOk">取 消</el-button>
                <el-button type="primary" @click="handleRouter">确定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import { queryDic } from "common/src/api/dictionary";
import { queryProfession } from "common/src/api/minor/minorMajorManager";
import UTILS from "common/src/utils/utils";
import { findProfessionByParam } from "common/src/api/culture/cultruescheme";
import { downloadfile } from "common/src/api/upload";
import {
    queryRelevanceList,
    cancelRelevanceScheme,
    autoRelevanceScheme,
    relevanceScheme,
    batchCancelRelevanceScheme,
    batchRelevanceScheme,
    countNeedBindSchemeStudent,
    bindSchemeStudent
} from "common/src/api/minor/culturePlanRelevance";
import { getSessionUser } from "common/src/api/session";
import { queryAdvancedLevel } from "common/src/api/minor/collegemajor";
import { queryMinorCultureSchemeList } from "common/src/api/minor/minorCultureScheme";
import mixin from 'common/src/mixins/index';
export default {
    mixins: [mixin],
    data() {
        return {
            dialogVisible: false,
            canSelectFaculty: true,
            templateRadio: 0,
            minorNameId: 0,
            dialogOk: false,
            chooseRows: [],
            studentId: 0,
            entranceTerm: 0,
            type: 0,
            queryParams: {
                grade: "",
                college: "",
                advancedLevel: "",
                profession: "",
                status: "",
                keyWord: ""
            },
            dialogForm: {
                grade: "",
                college: "",
                advancedLevel: "",
                profession: "",
                cultureSchemeName: ""
            },
            options: {
                college: [],
                profession: [],
                dialogProfession: [],
                cultureStatus: [],
                advancedLevel: [],
                pushStatus: [
                    { label: "未关联", value: 1 },
                    { label: "已关联", value: 2 }
                ]
            },
            page: {
                pageNum_: 1,
                pageSize_: 20
            },
            culturePage: {
                pageNum_: 1,
                pageSize_: 20
            },
            tipsData: {},
            tableData: {},
            schemeTableData: {},
            associateModelType: '',
            canAssociateNum: '' //自动关联培养方案个数
        };
    },
    created() {},
    mounted() {
        if (!this.$checkMinor()) return;
        //this.getType();
        this.getOptions();
        //this.initAdvancedLevel("0");
    },
    activated() {},
    methods: {
        //获取当前登录角色权限信息
        getType() {
            // getSessionUser().then(res => {
            //     if ((res.code = 200)) {
            //         //校管理员登录
            //         if (
            //             res.data.user.innerRoles.join(",").indexOf("1") >= 0 &&
            //             res.data.user.currentRole == "1"
            //         ) {
            //             //学院不可选择
            //             this.canSelectFaculty = true;
            //             this.queryParams.college = "";
            //             this.queryParams.profession = "";
            //             this.initCulturePlanList();
            //             // this.dialogForm.college = "";
            //             // this.dialogForm.profession = "";
            //             //初始化培养方案信息
            //             //this.initCultureSchemeData();
            //             //院教务员登录
            //         } else if (
            //             res.data.user.innerRoles.join(",").indexOf("2") >= 0 &&
            //             res.data.user.innerRoles.join(",").indexOf("1") == -1 &&
            //             res.data.user.currentRole == "1"
            //         ) {
            //             //学院不可选择
            //             this.canSelectFaculty = false;
            //             this.queryParams.college = this.options.college[0].value;
            //             this.queryCampusProfessions(1);
            //             this.initCulturePlanList();
            //             // this.dialogForm.college = this.options.college[0].value;
            //             // this.queryCampusProfessions(2);
            //             //初始化培养方案信息
            //            // this.initCultureSchemeData();
            //         }
            //     }
            // });
            if (this.global.isAcdemicDean) {
                this.canSelectFaculty = false;
                this.queryParams.college = this.options.college[0] && this.options.college[0].value;   
                this.queryCampusProfessions(1); 
                this.initCulturePlanList();
            }else if (this.global.isAdmin){
                this.canSelectFaculty = true;
                this.initCulturePlanList();
            }
        },
        getOptions() {
            let data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["X_YX"]
            };
            queryDic(data).then(res => {
                this.options.college = [];
                UTILS.fillSelect(
                    {
                        college: "X_YX"
                    },
                    res.data,
                    this.options
                );
                this.getType();
            });
        },
        //表格复选框选中或取消
        handleSelectionChange(val) {
            this.chooseRows = val;
        },
        getPushLable(value) {
            const pushStatu = this.options.pushStatus.find(
                t => t.value === value
            );
            if (pushStatu === "{}") {
                return value;
            } else {
                return pushStatu.label;
            }
        },
        initAdvancedLevel(isOnCampus) {
            let params = {
                isOnCampus: isOnCampus
            };
            this.options["advancedLevel"] = [];
            queryAdvancedLevel(params).then(res => {
                if (res.code == 200) {
                    for (let key = 0; key < res.data.length; key++) {
                        this.options["advancedLevel"].push({
                            value: res.data[key].advancedLevelCode,
                            label: res.data[key].advancedLevelName
                        });
                    }
                }
            });
        },
        initCulturePlanList() {
            if (!this.$checkMinor()) return;
            //初始化培养方案信息
            let param = {
                projId: 1,
                pageNum_: this.page.pageNum_,
                pageSize_: this.page.pageSize_,
                statusRelation: this.queryParams.status,
                entranceTerm: this.queryParams.grade,
                departmentId: this.queryParams.college,
                major: this.queryParams.profession,
                studentName: this.queryParams.keyWord,
                // advancedLevelCode: this.queryParams.advancedLevel
            };
            queryRelevanceList(param).then(res => {
                if (res.code == 200) {
                    this.tableData = res.data;
                }
            });
        },
        initDialog() {
            this.showTerm = true;
            this.postForm.grade = "";
            this.postForm.trainingLevel = "";
            this.postForm.term = "";
            this.postForm.startTime = "";
            this.postForm.endTime = "";
            this.postForm.relationSelectCourse = "";
            this.initColleges = this.options.college.map(c => {
                return { key: c.value, label: c.label };
            });
            if (this.$refs.transfer1)
                this.$refs.transfer1.leftChecked.length = 0;
            if (this.$refs.postForm) this.$refs.postForm.resetFields();
            this.showDialog = true;
        },
        initCultureSchemeData() {
            if (!this.$checkMinor()) return;
            let params = {
                pageNum_: this.culturePage.pageNum_,
                pageSize_: this.culturePage.pageSize_,
                minorGrade: this.dialogForm.grade,
                collegeCode: this.dialogForm.college,
                // advancedLevelCode: this.dialogForm.advancedLevel,
                major: this.dialogForm.profession,
                name: this.dialogForm.cultureSchemeName,
                projId: 1,
                status: 1
            };
            this.templateRadio = 0;
            queryMinorCultureSchemeList(params).then(res => {
                if (res.code == 200) {
                    this.schemeTableData = res.data;
                }
            });
        },
        //重置查询条件
        resetQuery() {
            this.queryParams.grade = "";
            if (this.canSelectFaculty) {
                this.queryParams.college = "";
                this.options.profession = [];
            }else {
                this.queryParams.college = this.options.college[0].value;
                this.queryCampusProfessions(1);
            }
            this.queryParams.advancedLevel = "";
            this.queryParams.profession = "";
            this.queryParams.status = "";
            this.searchData();
        },
        //重置方案查询条件
        resetSchemeForm() {
            this.dialogForm.grade = "";
            this.dialogForm.cultureSchemeName = '';
            if (this.canSelectFaculty) {
                this.dialogForm.college = "";
                this.options.dialogProfession = [];
            }else {
                this.dialogForm.college = this.options.college[0].value;
                this.queryCampusProfessions(2);
            }
            this.dialogForm.advancedLevel = "";
            this.dialogForm.profession = "";
            this.culturePage.pageNum_ = 1;
            this.initCultureSchemeData();
        },
        searchRelevance() {
            this.searchData();
        },
        //点击筛选查询数据
        searchData() {
            //调用查询列表的方法
            this.page.pageNum_ = 1;
            this.initCulturePlanList();
        },
        //点击方案查询方案数据
        searchSchemeData() {
            this.culturePage.pageNum_ = 1;
            this.initCultureSchemeData();
        },
        inputSearch() {
            this.culturePage.pageNum_ = 1;
            this.initCultureSchemeData();
        },
        cancelRelevance(row) {
            if (!this.$checkMinor()) return;
            //取消关联
            let params = {
                id: row.id,
                cultureId: row.cultureId,
                studentId: row.studentId
            };
            this.$confirm("您确定要对已选择的取消关联？", "取消关联", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    cancelRelevanceScheme(params).then(res => {
                        if (res.code == 200) {
                            this.$message({
                                type: "success",
                                message: "取消关联成功!"
                            });
                            this.searchData();
                        }
                    });
                })
                .catch(() => {
                    this.$message.error(res.msg);
                });
        },
        batchCancelRelevance() {
            if (!this.$checkMinor()) return;
            if (this.chooseRows.length > 0) {
                let flag = true;
                this.chooseRows.forEach(e => {
                    if (e.statusRelation === 1) {
                        flag = false;
                        return flag;
                    }
                });

                if(!flag){
                    this.$message({
                        message: "学生已取消关联,请选择已关联的学生。",
                        type: "warning"
                    });
                }

                if (flag) {
                    let relIdLists = [];
                    this.chooseRows &&
                        this.chooseRows.forEach(e => {
                            relIdLists.push({
                                id: e.id,
                                cultureId: e.cultureId,
                                studentId: e.studentId
                            });
                        });
                    let paramsData = {
                        relIdList: relIdLists
                    };
                    //批量取消关联
                    this.$confirm("您确定要对已选择的取消关联？", "取消关联", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning"
                    })
                        .then(() => {
                            batchCancelRelevanceScheme(paramsData).then(res => {
                                if (res.code == 200) {
                                    this.$message({
                                        type: "success",
                                        message: "取消关联成功!"
                                    });
                                    this.searchData();
                                }
                            });
                        })
                        .catch(() => {
                            this.$message({
                                type: "info",
                                message: res.msg
                            });
                        });
                }
            } else {
                this.$message({
                    message: "请选择要取消关联的学生。",
                    type: "warning"
                });
                return;
            }
        },
        relevanceCultureScheme(row) {
            if (!this.$checkMinor()) return;
            if (row.statusRelation === 2) {
                this.$message.error(
                    "您选择的学生已关联培养方案！请选择还未关联培养方案的学生。"
                );
            } else {
                this.templateRadio = 0;
                this.minorNameId = row.schoolMinorId;
                this.studentId = row.studentId;
                this.type = 1;
                this.entranceTerm = row.entranceTerm;
                //关联方案
                this.$refs.relevanceDialog.open();
            }
        },
        batchRelevanceCultureScheme() {
            if (!this.$checkMinor()) return;
            let flag = true;
            if (this.chooseRows.length > 0) {
                this.chooseRows.forEach(e => {
                    if (e.statusRelation === 2) {
                        flag = false;
                        return flag;
                    }
                });

                if(!flag){
                    this.$message({
                        message:
                            "您选择的学生已关联培养方案！请选择还未关联培养方案的学生。",
                        type: "warning"
                    });
                }

                if (flag) {
                    //批量关联方案
                    this.templateRadio = 0;
                    this.$refs.relevanceDialog.open();
                    this.type = 2;
                }
            } else {
                this.$message({
                    message: "请选择要关联的学生",
                    type: "warning"
                });
                return;
            }
        },
        //自动关联
        autoAssociate() {
            /* yytiand */
            let selectedStudentData = [];
            if (this.chooseRows && this.chooseRows.length) {
                this.chooseRows.forEach(row => {
                    selectedStudentData.push(row.studentId);
                });
            }
            if ( selectedStudentData.length == 0 ) {
                this.$message({
                    type: "warning",
                    message: "请先选择要关联的学生"
                });
                return;
            }
            let param = {
                projId: 1,
                pageNum_: this.page.pageNum_,
                pageSize_: this.page.pageSize_,
                statusRelation: this.queryParams.status,
                entranceTerm: this.queryParams.grade,
                departmentId: this.queryParams.college,
                major: this.queryParams.profession,
                studentName: this.queryParams.keyWord,
                studentIdList: selectedStudentData
                // advancedLevelCode: this.queryParams.advancedLevel
            };
            if (!this.$checkMinor()) return;
            countNeedBindSchemeStudent(param).then(res => {
                if (res.code == 200) {
                    if (res.data === 0) {
                        this.$message.error(res.msg);
                        return;
                    }
                    this.associateModelType = "auto";
                    this.dialogOk = true;
                    this.canAssociateNum = res.data;
                    //自动关联培养方案
                    // this.$confirm(
                    //     "你确定要自动关联" + res.data + "人, 是否继续?",
                    //     "提示",
                    //     {
                    //         confirmButtonText: "确定",
                    //         cancelButtonText: "取消",
                    //         type: "warning"
                    //     }
                    // ).then(() => {
                    //     bindSchemeStudent(param).then(e => {
                    //         if (e.code == 200) {
                    //             this.tipsData = e.data;
                    //             this.dialogOk = true;
                    //             this.newId = id;
                    //         }
                    //     });
                    // });
                }
            });
        },
        //查询专业
        queryCampusProfessions(type) {
            let collegeCode = "", minorGrade = '';
            if (type === 1) {
                collegeCode = this.queryParams.college;
                minorGrade = this.queryParams.grade;
                this.queryParams.profession = "";
                this.options.profession = [];
            } else if (type === 2) {
                collegeCode = this.dialogForm.college;
                this.dialogForm.profession = "";
                this.options.dialogProfession = [];
                minorGrade = this.dialogForm.grade;
            }
            let params = {
                minorGrade: minorGrade,
                collegeCode: collegeCode
            };
            queryProfession(params).then(res => {
                if (res.code == 200) {
                    type === 1 && (this.options.profession = res.data);
                    type === 2 && (this.options.dialogProfession = res.data);
                }
            });
        },
        //取消弹出框
        closeSchemeDialog() {
            this.$refs.relevanceDialog.close();
        },
        //确定培养方案关联
        confirmSchemeDialog() {
            if (!this.$checkMinor()) return;
            if (this.type === 1) {
                if (this.templateRadio > 0) {
                    let params = {
                        schoolMinorId: this.minorNameId,
                        cultureId: this.templateRadio,
                        studentId: this.studentId,
                        entranceTerm: this.entranceTerm
                    };
                    relevanceScheme(params).then(res => {
                        if (res.code == 200) {
                            this.$refs.relevanceDialog.close();
                            this.searchData();
                        } else {
                            this.$message.error(res.msg);
                        }
                    });
                } else {
                    this.$message({
                        message: "请先选择需要关联的培养方案。",
                        type: "warning"
                    });
                }
            } else {
                if (this.templateRadio > 0) {
                    let relIdLists = [];
                    this.chooseRows &&
                        this.chooseRows.forEach(e => {
                            relIdLists.push({
                                schoolMinorId: e.schoolMinorId,
                                cultureId: this.templateRadio,
                                studentId: e.studentId,
                                entranceTerm: e.entranceTerm
                            });
                        });
                    let paramsData = {
                        relIdList: relIdLists
                    };
                    batchRelevanceScheme(paramsData).then(res => {
                        if (res.code == 200) {
                            this.$refs.relevanceDialog.close();
                            this.searchData();
                            this.type = 0;
                        } else {
                            this.$message.error({
                                type: "info",
                                message: res.msg
                            });
                        }
                    });
                } else {
                    this.$message({
                        message: "请先选择需要关联的培养方案。",
                        type: "warning"
                    });
                }
            }
        },
        //分页查询
        pageChange(page) {
            this.page.pageNum_ = page.pageNum;
            this.page.pageSize_ = page.pageSize;
            this.initCulturePlanList();
        },
        //弹出分页查询
        schemeChangePage(page) {
            this.culturePage.pageNum_ = page.pageNum;
            this.culturePage.pageSize_ = page.pageSize;
            this.initCultureSchemeData();
        },
        handleRouter() {
            this.dialogOk = false;
            if (this.associateModelType == 'auto') {
                let selectedStudentData = [];
                if (this.chooseRows && this.chooseRows.length) {
                    this.chooseRows.forEach(row => {
                        selectedStudentData.push(row.studentId);
                    });
                }
                let param = {
                    projId: 1,
                    pageNum_: this.page.pageNum_,
                    pageSize_: this.page.pageSize_,
                    statusRelation: this.queryParams.status,
                    entranceTerm: this.queryParams.grade,
                    departmentId: this.queryParams.college,
                    major: this.queryParams.profession,
                    studentName: this.queryParams.keyWord,
                    studentIdList: selectedStudentData
                };
                bindSchemeStudent(param).then(e => {
                    if (e.code == 200) {
                        this.tipsData = e.data || {};
                        this.dialogOk = true;
                        this.associateModelType = 'result';
                        //this.newId = id;
                    }
                });
            }else {
                this.searchData();
            }
        },
        cancelOk() {
            this.dialogOk = false;
            if (this.associateModelType == 'result') {
                this.searchData();
            }
        },
        //下载
        downloadfile() {
            downloadfile(this.tipsData.objectkey);
        },
        relevanceDialogClose() {
            this.templateRadio = 0;
        },
        previewCulture(row) {
            this.$router.push({
                name: 'minorCultureSchemeView',
                params: {
                    id: row.cultureId,
                    title: row.cultureName,
                    currentPath: this.$route.path
                }

            })
        }
    }
};
</script>
<style scoped>
.first_title {
    font-size: 18px;
    font-family: "微软雅黑";
    color: #2b3b4e;
    padding: 0px 0px 16px;
}
.btn {
    text-align: right;
    padding: 0px 0px 16px;
}
.title_div {
    font-size: 18px;
    font-weight: 500;
    font-family: 微软雅黑;
    margin: 16px 0px 0 0px;
}
.search_div {
    margin: 15px 0 16px 0;
}
</style>